﻿@using Radzen
@using System.Linq.Dynamic.Core
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.JSInterop
@using Microsoft.AspNetCore.Components.Rendering
@typeparam TValue
@inherits DropDownBase<TValue>
@if (Visible)
{
    <div @ref="@Element" style="@Style" @attributes="Attributes" class="@GetCssClass()" tabindex="@(Disabled ? "-1" : $"{TabIndex}")" @onkeydown="@OnKeyDown" id="@GetId()">
        <div class="rz-helper-hidden-accessible">
            <input name="@Name" readonly="@ReadOnly" disabled="@Disabled" type="text" />
        </div>
        @if (AllowFiltering || (Multiple && AllowSelectAll))
        {
            <div class=" rz-listbox-header rz-helper-clearfix rz-listbox-header-w-checkbox">
                @if (Multiple)
                {
                    @if (AllowSelectAll)
                    {
                    <div class="rz-chkbox " @onclick="@SelectAll">
                        <div class="rz-helper-hidden-accessible">
                            <input id="@($"{UniqueID}sa")" readonly="readonly" type="checkbox">
                        </div>
                        <div class="@(IsAllSelected() ? "rz-chkbox-box rz-state-active" : "rz-chkbox-box")">
                            <span class="@(IsAllSelected() ? "rz-chkbox-icon rzi rzi-check" : "rz-chkbox-icon")"></span>
                        </div>
                    </div>
                    }
                    @if (AllowSelectAll && !AllowFiltering && !string.IsNullOrEmpty(Placeholder))
                    {
                        <label for="@($"{UniqueID}sa")" class="rz-dropdown-label rz-inputtext" style="width:100%;">@Placeholder</label>
                    }
                }
                @if (AllowFiltering)
                {
                    <div class="rz-listbox-filter-container">
                        <input id="@SearchID" @ref="@search" disabled="@Disabled" class="rz-inputtext" role="textbox" type="text" placeholder="@Placeholder"
                               @onchange="@((args) => OnFilter(args))" @onkeydown="@((args) => OnFilterKeyPress(args))" value="@searchText" @onkeydown:stopPropagation="true"
                               @oninput=@(args => { searchText = $"{args.Value}"; SearchTextChanged.InvokeAsync(searchText);}) />
                        <span class="rz-listbox-filter-icon rzi rzi-search"></span>
                    </div>
                }
            </div>
        }
        @if (View != null)
        {
            <div class="rz-listbox-list-wrapper">
                <ul @ref="list" class="rz-listbox-list">
                    @RenderItems()
                </ul>
            </div>
        }
    </div>
}